package com.project.service;

import com.project.entity.User;
import com.project.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public User findOneByUserName(String userName) {
        return userMapper.findOne(userName);
    }

    public void save(User user) {
        userMapper.save(user);
    }


    public User getInfo(String userName) {
        return userMapper.findOne(userName);
    }

    public void update(User user) {
        if (user.getNickName() == null ) {
            user.setNickName("");
        }
        if(user.getPhone() == null){
            user.setPhone("");
        }
        if (user.getIdentityNum() == null){
            user.setIdentityNum("");
        }
        if (user.getAddress() ==null){
            user.setAddress("");
        }if (user.getRealName() == null){
            user.setRealName("");
        }

        userMapper.update(user);
    }
}
